'''
Copyright: 
Descripttion: 
version: 
Author: chengx
Date: 2021-04-24 11:07:09
LastEditors: chengx
LastEditTime: 2021-05-30 20:18:12
'''


import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from skfuzzy.cluster import cmeans



def myFCM(train,c=10,m=2):
    """
    Parameters: train : 训练数据
                c     : 聚类数量
                m     : 隶属度的因子
    Description:
    Returns:    index : 每一类的具体波段号
                count : 每一类的数量
    """
    center, u, u0, d, jm, p, fpc = cmeans(train,c, m, error=0.005, maxiter=1000,seed=10)
    for i in u:
        label = np.argmax(u, axis=0) #将所有特征分类
    
    count = np.bincount(label) # 统计每类的数量

    index=[]
    for i in np.unique(label):
        idx = np.argwhere( label ==i)
        # print('i:{}'.format(i),idx.reshape(1, -1).squeeze(0))# 将每类索引提取出来
        index.append(idx.reshape(1, -1).squeeze(0))


    # print('FCM clustering over!')
    return index,count